/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.wdm.beans;

import java.util.ArrayList;
import java.util.List;
import org.wdm.utils.BusUtils;

/**
 *
 * @author thanasis
 */
public class Bus {
    private String route;
    private List<BusStop> going;
    private List<BusStop> returning;

    public Bus() {
        going = new ArrayList<BusStop>();
        returning = new ArrayList<BusStop>();
    }
    
    public void addToGoing(BusStop busStop){
        if(!going.contains(busStop)){
            going.add(busStop);
        }
    }
    
    public void addToReturning(BusStop busStop){
        if(!returning.contains(busStop)){
            returning.add(busStop);
        }
    }
    
    public List<BusStop> getGoing() {
        return going;
    }

    public void setGoing(List<BusStop> going) {
        this.going = going;
    }

    public List<BusStop> getReturning() {
        return returning;
    }

    public void setReturning(List<BusStop> returning) {
        this.returning = returning;
    }

    public String getRoute() {
        return route;
    }

    public void setRoute(String route) {
        this.route = route;
    }
    
    public double getGoingRouteDistance(String unit){
        return BusUtils.getRouteDistance(going, unit);
    }
    
     public double getReturningRouteDistance(String unit){
        return BusUtils.getRouteDistance(returning, unit);
    }
     
     /**
      * 
      * @param busStop
      * @return 3 contained in both, 1 contained in going, 2 contained in returning, -1 doesn't contained 
      */
     public int containsBusStop(BusStop busStop){
         if(going.contains(busStop) && returning.contains(busStop)){
             return 2;
         } else if(going.contains(busStop)){
             return 1;
         } else if(returning.contains(busStop)){
             return -1;
         } else {
             return 0;
         }
     }

    @Override
    public String toString() {
        return "route=" + route;
    }
}
